package com.sijiao.stockconsumer;

import com.sijiao.stockconsumer.service.IStockFlowService;
import com.sijiao.stockconsumer.service.IStockService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class Consumer {

    private IStockService stockService;
    private IStockFlowService stockFlowService;

    public Consumer(IStockService stockService, IStockFlowService stockFlowService) {
        this.stockService = stockService;
        this.stockFlowService = stockFlowService;
    }

    @KafkaListener(topics = {"${stock.consume}"})
    public void listen(ConsumerRecord<?, ?> record) throws IOException {
        stockFlowService.insertFlow(1,0L, 1L, 1L);
        stockService.changeStock(1L, 1L);
    }


}
